layui.use(['form', 'table', 'layer', 'laydate'], function (form, table, layer, laydate) {
    form.render();//重点在这里

    let punchApp = new Vue({
        el: "#approveId",
        data: {
            adminList: [],
        },
        methods: {},
        mounted() {
            const that = this;
            $.ajax({
                url: "../user/admin",
                async: false,
                type: 'get',
                success: function (data) {
                    that.adminList = data.obj;
                    console.log(that.adminList)
                }
            });
        }, updated() {
            form.render();
        }
    });

    //提交按钮监听
    form.on("submit(updateSubmit)", function (data) {
        let leavesInfo = {};
        leavesInfo = data.field;
        leavesInfo.userId = parseInt(Base64.decode(getToken()));
        console.log("用户请假信息:", JSON.stringify(leavesInfo));
        $.ajax({
            type: "post",
            url: "../leaves/add",
            data: JSON.stringify(leavesInfo),
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            success: function (data) {
                if (data.success) {
                    layer.msg(
                        '已提交，等待审核...',
                        {
                            icon: 1,
                            time: 1000
                        },
                        function () {
                            location.href="phone-main.html";
                        });
                } else {
                    layer.msg('提交失败', {icon: 2});
                }
            },
            error: function (o) {
            }
        });
        return false;
    });

    //返回 return
    $(document).on("click", "#returnShow", function () {
        window.location.href = "phone-main.html";
    });

    //开始时间
    layui.laydate.render({elem: '#beginTime', trigger: 'click', min: getCurrentDate(0)});
    //结束时间
    layui.laydate.render({elem: '#endTime', trigger: 'click', min: getCurrentDate(1)});

    //获取当前时间
    function getCurrentDate(num) {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var day = date.getDate() + num;
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (day >= 0 && day <= 9) {
            day = "0" + day;
        }
        // if (hours >= 0 && hours <= 9) {
        //     hours = "0" + hours;
        // }
        // if (minutes >= 0 && minutes <= 9) {
        //     minutes = "0" + minutes;
        // }
        // if (seconds >= 0 && seconds <= 9) {
        //     seconds = "0" + seconds;
        // }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + day;
        // + " " + hours + seperator2 + minutes
        // + seperator2 + seconds;
        return currentdate;
    }

});